<script>
	$(document).ready(function(){
        $('input[type="radio"]').click(function(){		
            if($(this).attr("value")=="Wali"){
                $("div#hub").show('slow');
            }
            if($(this).attr("value")=="Ayah"){
               $("div#hub").hide('slow');
            }
			if($(this).attr("value")=="Ibu"){
               $("div#hub").hide('slow');
            }
        });
    });
</script>
<!-- Edit Saudara Modal -->
<div class="modal fade" id="editSModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div id="editSaudara"></div>
		</div>
	</div>
</div>
<!-- end edit saudara modal -->

<!-- Edit Ortu Modal -->
<div class="modal fade" id="editOWModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div id="editOrtuWali"></div>
		</div>
	</div>
</div>
<!-- end edit ortu modal -->

<!-- Saudara Modal -->
<div class="modal fade" id="saudaraModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Tambah Saudara</h4>
      </div>
      <div class="modal-body">
		<?php 
			echo form_open_multipart('mr_saudara/add_exe', array('class' => 'form-horizontal', 'role' => 'form')); 
		?>
		<input type="hidden" name="nis" value="<?php echo $nis = $this->security->xss_clean($this->uri->segment(3));?>"/>					  
		
		<div class="form-group">
		<label class="col-sm-3 control-label">Hubungan Saudara</label>
		<div class="col-sm-9">
			<label class="radio-inline">
				<input type="radio" name="hubungan" value="Kakak" checked>
				Kakak
			</label>

			<label class="radio-inline">
				<input type="radio" name="hubungan" value="Adik">
				Adik
			</label>
		</div>
	  </div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">Nama Lengkap</label>
			<div class="col-sm-9">
				<input type="text" name="nama" class="form-control input-sm" placeholder="Nama Lengkap">
			</div>
		</div>
	  
	  <div class="form-group">
		<label class="col-sm-3 control-label">Jenis Kelamin</label>
		<div class="col-sm-9">
			<label class="radio-inline">
				<input type="radio" name="jk" value="L" checked>
				Laki-laki
			</label>

			<label class="radio-inline">
				<input type="radio" name="jk" value="P">
				Perempuan
			</label>
		</div>
	  </div>

	<div class="form-group">
		<label class="col-sm-3 control-label">Tanggal Lahir</label>
		<div class="col-sm-5">
			<input type="text" name="tgl_lahir" class="form-control input-sm tanggal" placeholder="Tanggal Lahir">
		</div>
	</div>					  
		
	<div class="form-group">
		<label class="col-sm-3 control-label">Nama Sekolah</label>
		<div class="col-sm-9">
		  <input type="text" name="nm_sekolah" class="form-control input-sm" placeholder="Nama Sekolah">
		</div>
	</div>
	
	<div class="form-group">
		<label class="col-sm-3 control-label">Kelas</label>
		<div class="col-sm-3">
		  <input type="text" name="kelas" class="form-control input-sm" placeholder="Kelas">
		</div>
	</div>
	
	<div class="modal-footer">
        <button type="submit" class="btn btn-default btn-sm" data-dismiss="modal">Batal</button>
        <button type="submit" onClick="validate_saudara()" class="btn btn-primary btn-sm">Tambahkan</button>
     </div>
	
		<?php 
			echo form_close();
		?>
      </div>      
    </div>
  </div>
</div>
<!-- end saudara modal -->

<!-- Ortu Modal -->
<div class="modal fade" id="ortuModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Tambah Orang Tua/Wali</h4>
      </div>
      <div class="modal-body">
	 
		<?php 
			echo form_open_multipart('mr_ortuwali/add_exe', array('class' => 'form-horizontal', 'role' => 'form')); 
		?>
		<input type="hidden" name="nis" value="<?php echo $nis = $this->security->xss_clean($this->uri->segment(3));?>"/>					  
		
		<div class="form-group">
		<label class="col-sm-3 control-label">Hubungan</label>
		<div class="col-sm-9">
			<label class="radio-inline">
				<input type="radio" name="hubungan" value="Ayah" checked>
				Ayah
			</label>

			<label class="radio-inline">
				<input type="radio" name="hubungan" value="Ibu">
				Ibu
			</label>
			
			<label class="radio-inline">
				<input type="radio" name="hubungan" id="wali" value="Wali">
				Wali
			</label>
		</div>
	  </div>
	  
		<div id="hub" style="display:none;">
		<div class="form-group">
			<label class="col-sm-3 control-label">Hubungan Wali</label>
			<div class="col-sm-9">
				<input type="text" name="hub_wali" class="form-control input-sm" placeholder="Hubungan Wali">
			</div>
		</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">Nama Lengkap</label>
			<div class="col-sm-9">
				<input type="text" name="nama" class="form-control input-sm" placeholder="Nama Lengkap">
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">Alamat</label>
			<div class="col-sm-9">
				<textarea name="alamat" class="form-control input-sm" rows="3" placeholder="Alamat Lengkap"></textarea>
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label">Kelurahan</label>
			<div class="col-sm-5">
				<input type="text" name="kel" class="form-control input-sm" placeholder="Kelurahan">
			</div>
		</div>	

		<div class="form-group">
			<label class="col-sm-3 control-label">Kecamatan</label>
			<div class="col-sm-5">
				<input type="text" name="kec" class="form-control input-sm" placeholder="Kecamatan">
			</div>
		</div>			
			
		<div class="form-group">
			<label class="col-sm-3 control-label">No. Tlp</label>
			<div class="col-sm-9">
			  <input type="text" name="tlp" class="form-control input-sm" placeholder="No. Tlp">
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">Email</label>
			<div class="col-sm-5">
			  <input type="text" name="email" class="form-control input-sm" placeholder="Email">
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label label-elba">Pekerjaan</label>
			<div class="col-sm-7">
				<select name="id_mr_pekerjaan" class="form-control form-elba input-sm">
					<?php foreach ($list_pekerjaan->result() as $row){ ?>
						<option value="<?php echo $row->id_mr_pekerjaan; ?>"><?php echo $row->pekerjaan; ?></option>
					<?php } ?>
				</select>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">Jabatan</label>
			<div class="col-sm-5">
			  <input type="text" name="jabatan" class="form-control input-sm" placeholder="Jabatan">
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label label-elba">Gaji</label>
			<div class="col-sm-7">
				<select name="id_mr_gaji" class="form-control form-elba input-sm">
					<?php foreach ($list_gaji->result() as $row){ ?>
						<option value="<?php echo $row->id_mr_gaji; ?>"><?php echo $row->gaji; ?></option>
					<?php } ?>
				</select>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">Kantor</label>
			<div class="col-sm-7">
			  <input type="text" name="kantor" class="form-control input-sm" placeholder="Nama Kantor">
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">Alamat Kantor</label>
			<div class="col-sm-9">
				<textarea name="alamat_kantor" class="form-control input-sm" rows="3" placeholder="Alamat Kantor"></textarea>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">No. Tlp. Kantor</label>
			<div class="col-sm-5">
			  <input type="text" name="tlp_kantor" class="form-control input-sm" placeholder="No. Tlp. Kantor">
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label">No. Fax Kantor</label>
			<div class="col-sm-5">
			  <input type="text" name="fax_kantor" class="form-control input-sm" placeholder="No. Fax Kantor">
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label label-elba">Pendidikan Terakhir</label>
			<div class="col-sm-7">
				<select name="id_mr_pendidikan" class="form-control form-elba input-sm">
					<?php foreach ($list_pendidikan->result() as $row){ ?>
						<option value="<?php echo $row->id_mr_pendidikan; ?>"><?php echo $row->pendidikan; ?></option>
					<?php } ?>
				</select>
			</div>
		</div>
		
		<div class="form-group">
		<label class="col-sm-3 control-label">Kewarganegaraan</label>
		<div class="col-sm-9">
			<label class="radio-inline">
				<input type="radio" name="warga" value="WNI" checked>
				WNI
			</label>

			<label class="radio-inline">
				<input type="radio" name="warga" value="WNA">
				WNA
			</label>
		</div>
	  </div>
	  
	  <div class="form-group">
		<label class="col-sm-3 control-label">Agama</label>
		<div class="col-sm-9">
			<?php 
			$i = 0;
			foreach ($list_agama->result() as $row){ 
			$i++;
			if($i == 1){
				$checked = "checked";
			}else{
				$checked = "";
			}

			?>
			<label class="radio-inline">
				<input type="radio" name="id_mr_agama" value="<?php echo $row->id_mr_agama; ?>" <?php echo $checked; ?>>
				<?php echo $row->agama; ?>
			</label>
			<?php } ?>
		</div>
	  </div>
		
		<div class="modal-footer">
			<button type="reset" class="btn btn-default btn-sm" data-dismiss="modal">Batal</button>
			<button type="submit" onClick="validate_ortu()" class="btn btn-primary btn-sm">Tambahkan</button>
		 </div>
	
		<?php 
			echo form_close();
		?>
      </div>      
    </div>
  </div>
</div>
<!-- end ortu modal -->

<div id="page-wrapper">
    <!-- row siswa -->
    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-default">
                <div class="panel-heading"><span class="judul-page">Data Siswa</span></div>
                <div class="panel-body">
				
					<table class="table table-striped table-bordered table-hover table-condensed">
					<?php 						
						foreach ($list as $row){ 
					?>
						<tr>
							<td class="col-sm-2">NIS/NVA</td>
							<td class="col-sm-10"><?php echo $row->nva.' / '.$row->nis; ?></td>
						</tr>
						<tr>
							<td class="col-sm-2">NIK</td>
							<td class="col-sm-10"><?php echo $row->nik; ?></td>
						</tr>
						<tr>
							<td class="col-sm-2">Nama Lengkap Siswa</td>
							<td class="col-sm-10"><?php echo $row->nm_lengkap; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Jenis Kelamin</td>
							<td class="col-sm-10"><?php if ($row->jk == 'L'){echo "Laki-laki";}else{echo "Perempuan";} ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Nama Panggilan</td>
							<td class="col-sm-10"><?php echo $row->nm_panggilan; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">TTL</td>
							<td class="col-sm-10"><?php echo $row->tmp_lahir.', '.date("d-m-Y", strtotime ($row->tgl_lahir));; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Alamat</td>
							<td class="col-sm-10"><?php echo $row->alamat; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">No. Tlp</td>
							<td class="col-sm-10"><?php echo $row->tlp; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Jarak</td>
							<td class="col-sm-10"><?php echo $row->jarak; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Transportasi</td>
							<td class="col-sm-10"><?php echo $row->trans; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Alamat Sekolah</td>
							<td class="col-sm-10"><?php echo $row->almt_sekolah; ?></td>
						</tr>
                    <?php 
						}						
					?>
					</table>
						
                </div> 
            </div>
        </div>
    </div>
    <!-- end row siswa -->
	
	<!-- row saudara -->
	<div class="row">
		<div class="col-sm-12">
			<div class="panel panel-default">
				<div class="panel-heading"><span class="judul-page">Data Saudara</span>
				<span class="pull-right">
					<a href="#" class="btn btn-warning btn-xs" data-toggle="modal" data-target="#saudaraModal"><span class="glyphicon glyphicon-plus"></span>&nbsp;Tambah Saudara</a>
				</span>
				<div class="clearfix"></div>
				</div>
                <div class="panel-body">
				<div id="konfirm"></div>
					<?php 									
						if(count($list_saudara)>0){
							foreach ($list_saudara as $row){ 
					?>	
					
					<table class="table table-striped table-bordered table-hover table-condensed">							
					
						<tr>
							<td style="background-color:#fcf8e3;" colspan="2">
								<span class="pull-left judul-hub"><?php echo $row->hubungan; ?></span>
								<span class=" pull-right">
									<a href="<?php echo site_url(); ?>mr_saudara/delete/<?php echo $row->id_mr_saudara;?>" onclick="return confirm('Yakin Anda akan menghapus data Saudara ini secara permanen?')"><span class="glyphicon glyphicon-trash"></span> Hapus</a>&nbsp;&nbsp;
									<a href="" data-toggle="modal" data-target="#editSModal" onclick="edit_saudara('<?php echo $row->id_mr_saudara;?>')" ><span class="glyphicon glyphicon-edit"></span> Edit</a>
								</span>
							</td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Nama Lengkap</td>
							<td class="col-sm-10"><?php echo $row->nama; ?></td>
						</tr>
				
						<tr>
							<td class="col-sm-2">Jenis Kelamin</td>
							<td class="col-sm-10"><?php if ($row->jk == 'L'){echo "Laki-laki";}else{echo "Perempuan";} ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Tanggal Lahir</td>
							<td class="col-sm-10"><?php echo date("d-m-Y", strtotime ($row->tgl_lahir));; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Nama Sekolah</td>
							<td class="col-sm-10"><?php echo $row->nm_sekolah; ?></td>
						</tr>
						
						<tr>
							<td class="col-sm-2">Kelas</td>
							<td class="col-sm-10"><?php echo $row->kelas; ?></td>
						</tr>	
						
					</table>
					<?php 
						}		
					}else{
				?>
					<table class="table table-striped table-bordered table-hover table-condensed">							
						<tr>
							<td class="col-sm-12">Belum ada data Saudara</td>
						</tr>								
					</table>
				<?php
					}
				?>						
				</div> 
            </div>	
		</div>
	</div>
	<!-- end row saudara -->
	
	<!-- row ortu/wali -->
	<div class="row">
		<div class="col-sm-12">
			<div class="panel panel-default">
				<div class="panel-heading"><span class="judul-page">Data Orang Tua/Wali</span>
				<span class="pull-right">
					<a href="#" class="btn btn-warning btn-xs" data-toggle="modal" data-target="#ortuModal"><span class="glyphicon glyphicon-plus"></span>&nbsp;Tambah Orang Tua/Wali</a>
				</span>
				<div class="clearfix"></div>
				</div>
                <div class="panel-body">
				
							<?php 									
								if(count($list_ortuwali)>0){
									foreach ($list_ortuwali as $row){ 
							?>
							<table class="table table-striped table-bordered table-hover table-condensed">
							
								<tr>
									<td style="background-color:#fcf8e3;" colspan="2">
										<span class="pull-left judul-hub">
											<?php echo $row->hubungan; if ($row->hubungan == "Wali"){echo ", Hubungan Wali: ".$row->hub_wali;}?>
										</span>
										
										<span class=" pull-right">
											<a href="<?php echo site_url(); ?>mr_ortuwali/delete/<?php echo $row->id_mr_ortuwali;?>" onclick="return confirm('Yakin Anda akan menghapus data Orang Tua/Wali ini secara permanen?')"><span class="glyphicon glyphicon-trash"></span> Hapus</a>&nbsp;&nbsp;
											<a href="" data-toggle="modal" data-target="#editOWModal" onclick="edit_ortuwali('<?php echo $row->id_mr_ortuwali;?>')" ><span class="glyphicon glyphicon-edit"></span> Edit</a>
										</span>
									</td>
								</tr>

								<tr>
									<td class="col-sm-2">Nama Lengkap</td>
									<td class="col-sm-10"><?php echo $row->nama; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Alamat</td>
									<td class="col-sm-10"><?php echo $row->alamat; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Kelurahan</td>
									<td class="col-sm-10"><?php echo $row->kel; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Kecamatan</td>
									<td class="col-sm-10"><?php echo $row->kec; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">No. Tlp</td>
									<td class="col-sm-10"><?php echo $row->tlp; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Email</td>
									<td class="col-sm-10"><?php echo $row->email; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Pekerjaan</td>
									<td class="col-sm-10"><?php echo $row->pekerjaan; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Jabatan</td>
									<td class="col-sm-10"><?php echo $row->jabatan; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Gaji</td>
									<td class="col-sm-10"><?php echo $row->gaji; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Nama Kantor</td>
									<td class="col-sm-10"><?php echo $row->kantor; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Alamat Kantor</td>
									<td class="col-sm-10"><?php echo $row->alamat_kantor; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Tlp. Kantor</td>
									<td class="col-sm-10"><?php echo $row->tlp_kantor; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Fax Kantor</td>
									<td class="col-sm-10"><?php echo $row->fax_kantor; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Pendidikan Terakhir</td>
									<td class="col-sm-10"><?php echo $row->pendidikan; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Kwarganegaraan</td>
									<td class="col-sm-10"><?php echo $row->warga; ?></td>
								</tr>
								
								<tr>
									<td class="col-sm-2">Agama</td>
									<td class="col-sm-10"><?php echo $row->agama; ?></td>
								</tr>
								
							</table>
						<?php 
								}		
							}else{
						?>
							<table class="table table-striped table-bordered table-hover table-condensed">							
							<tr>
								<td class="col-sm-12">Belum ada data Orang Tua/Wali</td>
							</tr>								
							</table>
						<?php
							}
						?>
						
				</div> 
            </div>	
		</div>
	</div>
	<!-- end row ortu/wali -->
<!-- end page-wrapper -->
<script type="text/javascript">
    $('#saudaraModal').modal(options);
    $('#ortuModal').modal(options);
    $('#editSModal').modal(options);	
    $('#editOModal').modal(options);	
	
	function edit_saudara(id_mr_saudara){
		$.ajax({
			type: "POST",
			url : "<?php echo site_url(); ?>mr_saudara/edit",
			data: "id_mr_saudara="+id_mr_saudara,
			cache: false,
			success: function(response) {
				$('#editSaudara').html(response);
			}
		});
		return false;
	}	
	
	function edit_ortuwali(id_mr_ortuwali){
		$.ajax({
			type: "POST",
			url : "<?php echo site_url(); ?>mr_ortuwali/edit",
			data: "id_mr_ortuwali="+id_mr_ortuwali,
			cache: false,
			success: function(response) {
				$('#editOrtuWali').html(response);
			}
		});
		return false;
	}	
</script>

<script>
  function validate_ortu() {
    $("form").validate({
      rules: {
        nama: {
          required: true
        },
        alamat: {
          required: true
        },
        kel: {
          required: true
        },
        kec: {
          required: true
        },
        tlp: {
          required: true
        },
        email: {
          required: true
        },
      },
      messages: {
        nama: {
          required: "Nama harus diisi."
        },
        alamat: {
          required: "Alamat harus diisi."
        },
        kel: {
          required: "Kelurahan harus diisi."
        },
        kec: {
          required: "Kecamatan harus diisi."
        },
        tlp: {
          required: "Telepon harus diisi."
        },
        email: {
          required: "Email harus diisi."
        },
      }
    });

    var topicInputs = topics.find("input").attr("disabled", !inital);
  };
</script>

<script>
  function validate_saudara() {
    $("form").validate({
      rules: {
        nama: {
          required: true
        },
        tgl_lahir: {
          required: true
        },
      },
      messages: {
        nama: {
          required: "Nama harus diisi."
        },
        tgl_lahir: {
          required: "Tanggal lahir harus diisi."
        },
      }
    });

    var topicInputs = topics.find("input").attr("disabled", !inital);
  };
</script>